'''
Created on Aug 2, 2010

@author: adolfo

Unit test suite for the interfaces and classes defined in the module
`sms_gateway`.
'''

from ..sms_gateway import Message, SMSGateway, SMSListener
import logging
import unittest

_LOGGER = logging.getLogger("mx.org.came.tests.sms_gateway_test")


class SMSGatewayTest(unittest.TestCase):
    """Class that defines tests for the interface `SMSGateway`."""

    def setUp(self):
        """Sets up the data used by the unit test suite.
        Creates an instance of SMSGateway.
        """
        self.sms_gateway = SMSGateway()

    def test_start_service(self):
        """Tests start_service() raises a NotImplementedError.
        """
        self.assertRaises(NotImplementedError, self.sms_gateway.start_service)
    
    def test_stop_service(self):
        """Tests stop_service() raises a NotImplementedError.
        """
        self.assertRaises(NotImplementedError, self.sms_gateway.stop_service)
    
    def test_get_phone_number(self):
        """Tests get_phone_number() raises a NotImplementedError.
        """
        self.assertRaises(NotImplementedError
                          , self.sms_gateway.get_phone_number)
    
    def test_send_message(self):
        """Tests send_message() raises a NotImplementedError.
        """
        self.assertRaises(NotImplementedError
                          , self.sms_gateway.send_message
                          , None)
    
    def test_add_sms_listener(self):
        """Tests add_sms_listener() raises a NotImplementedError.
        """
        self.assertRaises(NotImplementedError
                          , self.sms_gateway.add_sms_listener
                          , None)
    
    def test_remove_sms_listener(self):
        """Tests remove_sms_listener() raises a NotImplementedError.
        """
        self.assertRaises(NotImplementedError
                          , self.sms_gateway.remove_sms_listener
                          , None)
    
class SMSListenerTest(unittest.TestCase):
    """Class that defines tests for the interface `SMSListener`."""

    def setUp(self):
        """Sets up the data used by the unit test suite.
        Creates an instance of SMSListener.
        """
        self.sms_listener = SMSListener()

    def test_message_received(self):
        """Tests message_received() raises a NotImplementedError.
        """
        self.assertRaises(NotImplementedError
                          , self.sms_listener.message_received
                          , [None, None]
                          , None)
    
class MessageTest(unittest.TestCase):
    """Class that defines tests for the class `Message`."""
    
    def setUp(self):
        """Sets up the data used by the unit test suite.
        Creates an instance of `Message`.
        """
        self.message = Message()

    def test_init(self):
        """Tests that the data is initialized properly upon creation."""
        self.assertEquals(len(self.message.data), 4
                , "message.data was expected to have 4 elements.")
        self.assertEquals(self.message.data[Message.UDH], ""
                , "UDH was not initialized to the text-message value: ''")
        self.assertEquals(self.message.data[Message.SENDER_PHONE_NUMBER], None
                , "SENDER_PHONE_NUMBER was not initialized to None")
        self.assertEquals(self.message.data[Message.RECEIVER_PHONE_NUMBER], None
                , "RECEIVER_PHONE_NUMBER was not initialized to None")
        self.assertEquals(self.message.data[Message.ORIGINAL_BINARY_MESSAGE]
                , None
                , "ORIGINAL_BINARY_MESSAGE was not initialized to None")

# This class was placed here because it may be useful to test implementations
# of SMSGateway.
class MessageRecordingListener(SMSListener):
    """SMSListeners that stores the received messages in a list."""
    
    def __init__(self):
        """Initializes the list where the messages are stored."""
        self.received_messages = []
        
    def message_received(self, message, notifier):
        """Adds the received message to the list."""
        self.received_messages.append(message)


if __name__ == '__main__':
    unittest.main()
